#include<stdio.h>
#include<stdlib.h>

char Arr[15][15] = {};
char X = 0,Y = 0; 
char Now = -1;

char print(char n); 
void show(void);
void act(void);
int judge(int a,int b);

int main(int argc,const char* argv[])
{
	while(1)
	{
		show();
		if(!(judge(0,1) || judge(1,0) ||judge(1,-1) ||judge(1,1)))
		{
			Now = - Now;
		}
		else
		{
			return 0;
		}
		act();
	}
}

char print(char n)
{
	char ch = ' ';
	switch(n)
	{
		case 0: ch = '*'; break;
		case 1: ch = '@'; break;
		case -1: ch = 'O'; break;
	}
	return ch;
}

void show(void)
{
	system("clear");
	printf("  ");
	for(int i=0;i<15;i++)
	{
		printf(" %2d",i);
	}
	printf("\n");
	for(int i=0;i<15;i++)	
	{
		printf("%2d ",i);
		for(int j=0;j<15;j++)
		{
			printf(" %c ",print(Arr[i][j]));
		}
		printf("\n");
	}
}

void act(void)
{
	printf("请输入%c棋子的坐标:",print(Now));
	scanf("%hhd%hhd",&X,&Y);
	if(!(X>=0 && X<=14 && Y>=0 && Y<=14 && Arr[X][Y] == 0))
	{
		printf("该坐标不能落子,请重新输入。\n");
		act();
	}
	else
	{
		Arr[X][Y] = Now;
	}
}

int judge(int a,int b)
{
	int cunt = 1;
	for(int i=-4;i<=4;i++)
	{
		if(X+i<0||Y+i<0)
		{
			continue;
		}
		if(X+i>=14||Y+i>=14)
		{
			break;
		}
		if(Arr[X+i*a][Y-i*b] == Now && Arr[X+(i+1)*a][Y-(i+1)*b] == Now)
		{
			cunt++;
		}
		else
		{
			cunt = 1;
		}
		if(cunt >= 5)
		{
			printf("%c棋获胜",print(Now));
			return Now;
		}
	}
	return 0;
}
